package com.chixing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chixing.entity.CouponAll;
import com.chixing.entity.CustomerCoupon;
import com.chixing.mapper.CouponAllMapper;
import com.chixing.mapper.CustomerCouponMapper;
import com.chixing.service.ICustomerCouponService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author shy
 * @since 2022-10-20
 */
@Service
public class CustomerCouponServiceImpl extends ServiceImpl<CustomerCouponMapper, CustomerCoupon> implements ICustomerCouponService {
    @Autowired
    private CustomerCouponMapper customerCouponMapper;

    //查询用户有效的优惠卷
    @Override
    public List<CustomerCoupon> getbyall(CustomerCoupon customerCoupon) {
//        QueryWrapper<CustomerCoupon> wrapper = new QueryWrapper<>();
//        wrapper.eq("cust_id",custId);
////        wrapper.eq("coupon_status",0); //0:未使用 1：已使用 2：已过期
//        wrapper.select("coupon_name","coupon_redemption_code","coupon_status","cust_hold_number");
//        List<CustomerCoupon> customerCouponList = customerCouponMapper.selectList(wrapper);

        List<CustomerCoupon> customerCoupons = customerCouponMapper.selectList(null);

        return customerCoupons;
    }

    @Override
    public List<CustomerCoupon> getAllCouponsByUserId(Integer customerId) {
        QueryWrapper<CustomerCoupon> wrapper = new QueryWrapper<>();
        wrapper.eq("cust_id",customerId);
         wrapper.eq("coupon_status",0); //0:未使用 1：已使用 2：已过期
        List<CustomerCoupon> customerCoupons = customerCouponMapper.selectList(wrapper);

        return customerCoupons;
    }

    @Override
    public CustomerCoupon getCouponByCouponNo(Integer couponNo) {
        QueryWrapper<CustomerCoupon> couponQueryWrapper = new QueryWrapper<>();
        couponQueryWrapper.eq("coupon_no",couponNo);

        return customerCouponMapper.selectOne(couponQueryWrapper);
    }


}
